//
//  HourseDetailVc.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/8.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "HourseDetailVc.h"
#import "StringTool.h"
#import "BdTV.h"
#import "config.h"
#import "NoDataCellDM.h"
#import "HourseDataManage.h"
#import "HourseDetailData.h"

#import "NearbyCell.h"
#import "HourseDetailCell.h"
#import "HourseCategoryCountCell.h"
#import "MapCell.h"
#import "CellBaseData.h"
#import "Tools.h"
#import "VcInterface.h"
#import "HourseDetailHeadViewCell.h"
#import "TxtReadVc.h"
#import "MapVc.h"
#import "DetailHouseTypeViewController.h"


#import "BaseNvc.h"
#import "DealerMineVc.h"


#import "DetailHouseTypeVc.h"
#import "DetailHouseTypeSubVc.h"
#import "HouseTypeViewController.h"
#import "UserModal.h"
#import "MBProgressHUD+MJ.h"
#import "WebViewVCV.h"

#import "CustomerInfoViewController.h"
#import "MiddleManMyVC.h"
#import "ThreeBtnSectionView.h"
#import "HourseDetailCellV2.h"
#import "CommentCellP.h"
#import "AddCommentCell.h"
#import "AddCommentVc.h"
#import "CommentShowVc.h"
#import "MJRefresh.h"
#import "CommentData.h"
#import "PhotoShowManage.h"



@interface HourseDetailVc ()<VcInterface,MWPhotoBrowserDelegate>
@property (nonatomic,strong)HourseDataManage *dm;
@property (nonatomic,strong)NodataCell *nodataCell;

@property (strong, nonatomic) NSArray *commentArray;
@property (nonatomic,strong)HourseDetailData *headData;

@property (nonatomic,strong)NSMutableDictionary *hightDic;

@property (strong, nonatomic) ThreeBtnSectionView *sv;

@property(nonatomic,assign) int tabIndex,pageIndex;

@property(nonatomic,assign) Boolean isFirstRead;
@property (strong, nonatomic) NSArray *photosArray;

@end

@implementation HourseDetailVc
@synthesize dataMod,dm,nodataCell,headData,hightDic,sv,commentArray,tabIndex,pageIndex,isFirstRead,photosArray;



- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    
    [self initView];
    
    
    [self refreshData];
}



-(void)initView{
    
    isFirstRead = true;
    
    BdTV *title = [[BdTV alloc]initWithFrame:CGRectMake(0, 0, PMW, 44)];
    [title.backBtn setTag:11];
    [title.backBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [[title doneBtn] removeFromSuperview];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:title];
    
    if (![StringTool isBlankString:dataMod.title]) {
        [title setMianTitle:dataMod.title];
    }else{
        [title setMianTitle:@"楼盘详情"];
    }
    
    [UserModal shareUserModel].premise = [StringTool isBlankString:dataMod.title]?@"无数据":dataMod.title;
    
    hightDic = [[NSMutableDictionary alloc]init];
    
    dm = [[HourseDataManage alloc]init];
    
    sv = [ThreeBtnSectionView creatView];
    [[sv btn1]setTag:30];
    [[sv btn1]addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [[sv btn2]setTag:31];
    [[sv btn2]addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [[sv btn3]setTag:32];
    [[sv btn3]addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];

    [self.tableView addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    
    [self.tableView.footer noticeNoMoreData];
}





-(void)refreshData{
    
    
    [nodataCell setState:nodataCellStateLoading];
    
    
    __weak typeof(self) bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        ResulteMod *mod =[dm refreshDetailData:dataMod.hourseId];
        
        bself.headData = mod.dataMod;
        
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (mod.resltState == ResultNetError) {//网络出错
                
                [bself.nodataCell setState:nodataCellStateNetError];
                
            }else if(mod.resltState == ResultFail){//服务器返回出错  要显示code状态码
                
                [bself.nodataCell setCodeErrorTip:mod.resultCode];
                
            }else{//返回正常
                
                if(bself.headData==nil){//没数据
                    
                    [bself.nodataCell setState:nodataCellStateNodata];
                }else{//有数据
                    
                    bself.pageIndex = 1;
                    [bself loadMore];
                    
                    [bself.nodataCell setState:nodataCellStateNorMal];
                    
                    [bself.tableView reloadData];
                }
            }
        });
    });
    
}


//评论
-(void)loadMore{
    
    if (!isFirstRead) {
        
        if (tabIndex==2) {
            [self.tableView.footer resetNoMoreData];
        }else{
            [self.tableView.footer noticeNoMoreData];
            return;
        }
    }
    isFirstRead = false;
    
    
    __weak typeof(self) bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        ResulteMod *mod = [dm refreshAllCommentData:bself.dataMod.hourseId pageIndex:pageIndex];

        NSArray *newData = mod.dataMod;
        if (newData.count>0) {
            
            NSMutableArray *array = [[NSMutableArray alloc]initWithArray:bself.commentArray];
            
            [array addObjectsFromArray:newData];
            
            bself.commentArray = array;
        }
        
    
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (mod.resltState == ResultNetError) {//网络出错
                
                [bself.nodataCell setState:nodataCellStateNetError];
                
            }else if(mod.resltState == ResultFail){//服务器返回出错  要显示code状态码
                
                [bself.nodataCell setCodeErrorTip:mod.resultCode];
                
            }else{//返回正常
                
                if(newData.count==0){//没数据
                    
                    [bself.nodataCell setState:nodataCellStateNodata];
                }else{//有数据
                    
                    pageIndex++;
                    
                    [bself.nodataCell setState:nodataCellStateNorMal];
                    
                    [bself.tableView reloadData];
                }
            }
            
            [bself.tableView.footer endRefreshing];
        });
    });
}



-(void)btnOnclick:(UIButton *)sender{
    
    switch (sender.tag) {
            
        case 11:
            
            [self.navigationController popViewControllerAnimated:YES];
            break;
            
        case 22:
            
        {
            if ([UserModal shareUserModel].userType == UserTypeTrader)
            {
                DealerMineVc *vc = [DealerMineVc new];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }else if ([UserModal shareUserModel].userType == UserTypeMiddleMan )
            {
                MiddleManMyVC *vc = [[MiddleManMyVC alloc]initWithNibName:@"MiddleManMyVC" bundle:nil];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            else
            {
                CustomerInfoViewController *vc = [[CustomerInfoViewController alloc]initWithNibName:@"CustomerInfoViewController" bundle:nil];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        }
            
            break;
            
            
        case 44://下载1
            
            if (![StringTool isBlankString:headData.saleBookUrl]) {
                
                WebViewVCV *vc = [[WebViewVCV alloc]init];
                [vc loadDataByUrl:headData.saleBookUrl];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                [vc setMainTitle:@"经纪人楼书"];
                
            }else{
                [MBProgressHUD showError:@"链接无效!"];
            }
            break;
            
        case 55://下载2
            
            if (![StringTool isBlankString:headData.customBookUrl]) {
                
                WebViewVCV *vc = [[WebViewVCV alloc]init];
                [vc loadDataByUrl:headData.customBookUrl];
                [self.navigationController pushViewController:vc animated:YES];
                [vc setMainTitle:@"客户楼书"];
                
            }else{
                [MBProgressHUD showError:@"链接无效!"];
            }
            
            break;
            
        case 66://优惠
            
        {
            TxtReadVc *vc = [[TxtReadVc alloc]init];
            vc.titleStr = @"买家优惠";
            vc.txtStr = headData.huiDetail;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 77://佣金
        {
            TxtReadVc *vc = [[TxtReadVc alloc]init];
            vc.titleStr = @"佣金结算";
            vc.attStr = headData.yongDetailAtt;
            
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 88://卖点
            
        {
            TxtReadVc *vc = [[TxtReadVc alloc]init];
            vc.attStr =  [[NSAttributedString alloc] initWithData:[headData.maiDetailHtml dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
            vc.titleStr = @"拓客卖点";
            
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 99://查看房型
            
        {
            
            DetailHouseTypeVc *vc = [[DetailHouseTypeVc alloc]initWithNibName:@"DetailHouseTypeVc" bundle:nil];
            vc.premisesId = self.dataMod.hourseId;
            [self.navigationController pushViewController:vc animated:YES];
            break;
            
        }
            
        case 56://刷新
            
            [self refreshData];
            break;
            
            
        case 73://right hourse
            
        {
            DetailHouseTypeVc *vc = [[DetailHouseTypeVc alloc]initWithNibName:@"DetailHouseTypeVc" bundle:nil];
            vc.premisesId = self.dataMod.hourseId;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
            
        case 30://详细信息
            
            tabIndex = 0;
            [self.tableView.footer noticeNoMoreData];
            [self.tableView reloadData];
            break;
            
        case 31://周边配套
            
            tabIndex = 1;
            [self.tableView.footer noticeNoMoreData];
            [self.tableView reloadData];
            break;
            
        case 32://点评
            
            tabIndex = 2;
            [self.tableView.footer resetNoMoreData];
             [self.tableView reloadData];
            break;
            
            
        case 13://添加评论
            
        {
            AddCommentVc *vc = [AddCommentVc new];
            vc.hourseId = dataMod.hourseId;
            [self.navigationController pushViewController:vc animated:YES];

        }
            break;

            
        default:
            break;
    }
}

-(void)btn1OnClick:(UIButton *)sender{
    
    CommentData *clikCm = [commentArray objectAtIndex:sender.tag];
    NSArray *picNames = clikCm.imgArray;
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSString *picUrl in picNames) {
        [array addObject:[MWPhoto photoWithURL:[NSURL URLWithString:picUrl]]];
    }
    
    photosArray = array;
    
    MWPhotoBrowser *br = [PhotoShowManage  getMWPhotoShowInstance:self];
    [br setCurrentPhotoIndex:0];
    [self.navigationController pushViewController:br animated:YES];
    
}

-(void)btn2OnClick:(UIButton *)sender{
    
    CommentData *clikCm = [commentArray objectAtIndex:sender.tag];
    NSArray *picNames = clikCm.imgArray;
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSString *picUrl in picNames) {
        [array addObject:[MWPhoto photoWithURL:[NSURL URLWithString:picUrl]]];
    }
    
    photosArray = array;
    
    MWPhotoBrowser *br = [PhotoShowManage  getMWPhotoShowInstance:self];
    [br setCurrentPhotoIndex:1];
    [self.navigationController pushViewController:br animated:YES];
    
}
-(void)btn3OnClick:(UIButton *)sender{
    
    
    CommentData *clikCm = [commentArray objectAtIndex:sender.tag];
    NSArray *picNames = clikCm.imgArray;
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSString *picUrl in picNames) {
        [array addObject:[MWPhoto photoWithURL:[NSURL URLWithString:picUrl]]];
    }
    
    photosArray = array;
    
    MWPhotoBrowser *br = [PhotoShowManage  getMWPhotoShowInstance:self];
    [br setCurrentPhotoIndex:2];
    [self.navigationController pushViewController:br animated:YES];
}





#pragma tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (headData&&headData.arrayData.count>0) {
        [self.tableView setScrollEnabled:YES];
        return 2;
    }else{
        [self.tableView setScrollEnabled:YES];
        return 1;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    if (section==1) {
        
        
        return sv;
    }else{
        return [UIView new];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==1) {
        return 44;
    }else{
        return 0;
    }
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (headData&&headData.arrayData.count>0) {
        
        if (section==0) {
            int count  = 1;
            
            if (headData) {
                count=1;
            }
            
            if (headData.houseCatCellData) {
                count=2;
            }
            return count;
            
        }else if (section==1){
            
            if (self.tabIndex==0) {
                return 1;
            }else if (self.tabIndex==1){
                return headData.arrayData.count;
            }else{
                return commentArray.count+1;
            }
            
        }else{
            return 0;
        }
        
    }else{
        
        return 1;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
//    NSNumber *hight = [hightDic objectForKey:indexPath];
    NSNumber *hight;
    
    if (headData!=nil&&headData.arrayData&&headData.arrayData.count>0) {
        
        if (indexPath.section==0) {
            
            if (indexPath.row==0) {
                
                if (hight) {
                    return hight.floatValue;
                }else{
                    CGFloat hight = [HourseDetailHeadViewCell getHight:headData withTableView:tableView];
                    
                    [hightDic setObject:[NSNumber numberWithFloat:hight] forKey:indexPath];
                    
                    return hight;
                }
            }else if(indexPath.row==1){
                
                if (hight) {
                    return hight.floatValue;
                }else{
                    CGFloat hight = [HourseCategoryCountCell getHight:headData.houseCatCellData withTableView:tableView];
                    
                    [hightDic setObject:[NSNumber numberWithFloat:hight] forKey:indexPath];
                    
                    return hight;
                }
                
            }else{
                return 0;
            }
        }else{
            
            
            if (self.tabIndex==0) {
                
                if (hight) {
                    return hight.floatValue;
                }else{
                    CGFloat hight = [HourseDetailCellV2 getHight:headData withTableView:tableView];
                    
                    [hightDic setObject:[NSNumber numberWithFloat:hight] forKey:indexPath];
                    
                    return hight;
                }
                
                
                
            }else if (self.tabIndex==1){
            

                CellBaseData *cellData = [headData.arrayData objectAtIndex:indexPath.row];
                
                
                if (cellData.CELL_STYLE==CELL_STYLE_NearBy) {
                    
                    if (hight) {
                        return hight.floatValue;
                    }else{
                        CGFloat hight = [NearbyCell getHight:cellData withTableView:tableView];
                        
                        
                        [hightDic setObject:[NSNumber numberWithFloat:hight] forKey:indexPath];
                        
                        return hight;
                    }
                    
                }else if(cellData.CELL_STYLE==CELL_STYLE_Detail){
                    
                    if (hight) {
                        return hight.floatValue;
                    }else{
                        CGFloat hight = [HourseDetailCell getHight:cellData withTableView:tableView];
                        [hightDic setObject:[NSNumber numberWithFloat:hight] forKey:indexPath];
                        
                        return hight;
                    }
                    
                }else if(cellData.CELL_STYLE==CELL_STYLE_HOURSE_MAP){
                    
                    if (hight) {
                        return hight.floatValue;
                    }else{
                        CGFloat hight = [MapCell getHight:cellData withTableView:tableView];
                        
                        [hightDic setObject:[NSNumber numberWithFloat:hight] forKey:indexPath];
                        
                        return hight;
                    }
                    
                }else{
                    
                    return 0;
                }

            }else{
            
                if (indexPath.row==0) {
                    return [AddCommentCell getHight:nil withTableView:tableView];
                }else{
                    
                    CommentData *data = [commentArray objectAtIndex:indexPath.row-1];
                    return [CommentCellP getHight:data withTableView:tableView];
                }
            }
        }
    }
    
    return self.tableView.frame.size.height;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (!headData||headData.arrayData.count==0) {
        if(!nodataCell){
            nodataCell = [[NodataCell alloc] initWithFrame:self.tableView.frame];
            [nodataCell setState:nodataCellStateLoading];
            [[nodataCell refreshBtn]setTag:56];
            [nodataCell.refreshBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
        }
        
        return nodataCell;
    }
    
    
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            
            static NSString *ID = @"HourseDetailHeadViewCell";
            HourseDetailHeadViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
            if (cell == nil)
            {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"HourseDetailHeadViewCell" owner:nil options:nil]lastObject];
                
                [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
                
                [cell.headView initView];
                
                
                [cell.headView.downloadBtn1 setBackgroundImage:[Tools getImgByColor:cell.headView.downloadBtn1.backgroundColor] forState:UIControlStateNormal];
                [cell.headView.downloadBtn1 setTag:44];
                [cell.headView.downloadBtn1 addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                
                [cell.headView.downLoadBtn2 setBackgroundImage:[Tools getImgByColor:cell.headView.downLoadBtn2.backgroundColor] forState:UIControlStateNormal];
                [cell.headView.downLoadBtn2 setTag:55];
                [cell.headView.downLoadBtn2 addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                
                [cell.headView.huiBtn setBackgroundImage:[Tools getImgByColor:cell.headView.huiBtn.backgroundColor] forState:UIControlStateNormal];
                [cell.headView.huiBtn setTag:66];
                [cell.headView.huiBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                
                [cell.headView.yongBtn setBackgroundImage:[Tools getImgByColor:cell.headView.yongBtn.backgroundColor] forState:UIControlStateNormal];
                [cell.headView.yongBtn setTag:77];
                [cell.headView.yongBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                
                [cell.headView.maiBtn setBackgroundImage:[Tools getImgByColor:cell.headView.maiBtn.backgroundColor] forState:UIControlStateNormal];
                [cell.headView.maiBtn setTag:88];
                [cell.headView.maiBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                
                [cell.headView.lookHourseBtn setBackgroundImage:[Tools getImgByColor:cell.headView.lookHourseBtn.backgroundColor] forState:UIControlStateNormal];
                [cell.headView.lookHourseBtn setTag:99];
                [cell.headView.lookHourseBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                
                [cell setData:(HourseDetailData*)headData nvc:self.navigationController];
            }
            
            return cell;
        }else{
            
            static NSString *ID = @"HourseCategoryCountCell";
            HourseCategoryCountCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
            if (cell == nil)
            {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"HourseCategoryCountCell" owner:nil options:nil]lastObject];
                
                [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
                [[cell lookBtn]setBackgroundImage:[Tools getImgByColor:cell.lookBtn.backgroundColor] forState:UIControlStateNormal];
                [[cell lookBtn]setTag:73];
                [[cell lookBtn]addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                
                [cell.leftBtn setBackgroundImage:[Tools getImgByColor:cell.leftBtn.backgroundColor] forState:UIControlStateNormal];
                [cell.rightBtn setBackgroundImage:[Tools getImgByColor:cell.rightBtn.backgroundColor] forState:UIControlStateNormal];
                
                
                [[cell leftBtn]addTarget:self action:@selector(FangXingBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
                
                
                [[cell rightBtn]addTarget:self action:@selector(FangXingBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
                
            }
            
            
            [cell setData:headData.houseCatCellData];
            
            return cell;
            
        }
    }else{
        
        if (self.tabIndex==0) {

            static NSString *ID = @"HourseDetailCellV2";
            HourseDetailCellV2 *cell = [tableView dequeueReusableCellWithIdentifier:ID];
            if (cell == nil)
            {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"HourseDetailCellV2" owner:nil options:nil]lastObject];
                [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
                [cell.lookMoreBtn setTag:99];
                [cell.lookMoreBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
            }
            
            [cell setMainData:headData];
            
            return cell;
            
            
        }else if (self.tabIndex==1){
        
            CellBaseData *cellData = [headData.arrayData objectAtIndex:indexPath.row];
            
            if (cellData.CELL_STYLE==CELL_STYLE_NearBy) {
                
                NearbyCell *cell = [NearbyCell cellWithTableView:tableView];
                
                [cell setData:(NearbyCellData*)cellData];
                
                return cell;
                
            }else if(cellData.CELL_STYLE==CELL_STYLE_Detail){
                
                HourseDetailCell *cell = [HourseDetailCell cellWithTableView:tableView];
                
                [cell setData:(NearbyCellData*)cellData];
                
                return cell;
                
            }else if(cellData.CELL_STYLE==CELL_STYLE_HOURSE_MAP){
                
                MapCell *cell = [MapCell cellWithTableView:tableView];
                
                [cell setData:(HourseMapCellData*)cellData];
                
                return cell;
                
            }else{
                
                return [UITableViewCell new];
            }
            
        }else{
            
            if (indexPath.row==0) {
                
                static NSString *ID = @"AddCommentCell";
                AddCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (cell == nil)
                {
                    cell = [[[NSBundle mainBundle]loadNibNamed:@"AddCommentCell" owner:nil options:nil]lastObject];
                    
                    
                    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
                    
                    [cell.addCommentBtn setTag:13];
                    [cell.addCommentBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
                }
                
                return cell;
                
            }else{
                
                CommentData *data = [commentArray objectAtIndex:indexPath.row-1];
                
                static NSString *ID = @"CommentCellP";
                CommentCellP *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (cell == nil)
                {
                    cell = [[[NSBundle mainBundle]loadNibNamed:@"CommentCellP" owner:nil options:nil]lastObject];
                    
                    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
                    
                    cell.commentLab.preferredMaxLayoutWidth = PMW-14-25-18;
                    
                    [cell.commentLab layoutIfNeeded];
                    
                    
                    [cell.imgBtn1 setTag:indexPath.row-1];
                    [cell.imgBtn1 addTarget:self action:@selector(btn1OnClick:) forControlEvents:UIControlEventTouchUpInside];
                    
                    [cell.imgBtn2 setTag:indexPath.row-1];
                    [cell.imgBtn2 addTarget:self action:@selector(btn2OnClick:) forControlEvents:UIControlEventTouchUpInside];
                    
                    [cell.imgBtn3 setTag:indexPath.row-1];
                    [cell.imgBtn3 addTarget:self action:@selector(btn3OnClick:) forControlEvents:UIControlEventTouchUpInside];
                }
                
                [cell setData:data];
                
                return cell;
            }
        }
    }
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (headData!=nil&&headData.arrayData.count>0) {
        
        CellBaseData *cellData;
        
        if (indexPath.section==0) {
            return;
        }
        
        
        cellData = [headData.arrayData objectAtIndex:indexPath.row];
        
        if (cellData.CELL_STYLE==CELL_STYLE_NearBy && self.tabIndex == 1) {
            if ( [cellData isKindOfClass:[NearbyCellData class]]) {
                
                NearbyCellData *data = (NearbyCellData*)cellData;
                if ([data.title isEqualToString:@"周边学校"] ) {
                    
                    TxtReadVc *vc = [[TxtReadVc alloc]init];
                    vc.titleStr = @"附近学校";
                    vc.subCategoryTitleStr = data.detail;
                    vc.txtStr = data.moreDetial;
                    [self.navigationController pushViewController:vc animated:YES];
                    
                }
                
                
            }
        }else if(cellData.CELL_STYLE==CELL_STYLE_Detail){
            
            if ( [cellData isKindOfClass:[NearbyCellData class]]) {
                
                NearbyCellData *data = (NearbyCellData*)cellData;
                if (![StringTool isBlankString:data.detail]) {
                    
                    TxtReadVc *vc = [[TxtReadVc alloc]init];
                    vc.titleStr = @"楼盘介绍";
                    vc.txtStr = data.detail;
                    [self.navigationController pushViewController:vc animated:YES];
                }
            }
            
        }else if(cellData.CELL_STYLE==CELL_STYLE_HOURSE_MAP){
            
            HourseMapCellData *data = (HourseMapCellData*)cellData;
            
            MapVc *vc =[[MapVc alloc]initWithLoc:data];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}



#pragma mark 房型被点击
-(void)FangXingBtnOnClick:(UIButton *)btn
{
    HouseTypeViewController *vc = [HouseTypeViewController new];
    vc.premiseshousingId = btn.tag;
    [self.navigationController pushViewController:vc animated:YES];
}



#pragma MWPhotoShowDelegate
#pragma mark - MWPhotoBrowserDelegate

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    
    return photosArray.count;
}


- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
    

    if (index < photosArray.count)
        return  [photosArray objectAtIndex:index];
    
    return nil;
}


@end
